<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <link th:include="/comm/header :: header"/>
    <script type="text/javascript">
        $(function () {
            var first='';
            $.get("/sys/user/getfirst",function(result){
                if(result.flag){
                    first=result.data;
                    var content = "<iframe frameborder=0 scrolling='auto' style='width:100%;height:99%' src="+first+"></iframe>";
                    $("#tt").tabs("add", {
                        title: "首页",
                        iconCls: "fa fa-home",
                        closable: false,
                        content: content
                    });
                }
            });

            // 初始化主题
            var initTheme = function (themeName) {
                if (themeName == null) {
                    themeName = $('#themeCss').attr('href').split('/').pop().split('.css')[0];
                    // 添加勾选状态
                    $(".themeItem ul li").removeClass('themeActive');
                    $('.themeItem ul li .' + themeName).parent().addClass('themeActive');
                    return;
                }
                var themeUrl = $('#themeCss').attr('href').split('/');
                themeUrl.pop();
                $('#themeCss').after('<link rel="stylesheet" href="' + themeUrl.join('/') + '/' + themeName + '.css" id="themeCss">');
                $('#themeCss').remove();

                // 添加勾选状态
                $(".themeItem ul li").removeClass('themeActive');
                $('.themeItem ul li .' + themeName).parent().addClass('themeActive');

            }

            initTheme(localStorage.getItem('superTheme'));

            // 左侧导航分类选中样式
            $.get("/sys/resource/getmenu", {async: true}, function (data) {
                for (var i = 0; i < data.length; i++) {
                    var menulist = "<ul>"
                    $.each(data[i].children, function (key, val) {
                        menulist += "<li data-url='";
                        if (val.attributes) {
                            menulist += val.attributes['url'];
                        }
                        menulist += "'><i class='" + val.iconCls + "' aria-hidden=true></i> ";
                        menulist += val.text;
                        menulist += "</li>";
                    });
                    menulist += "</ul>"
                    $('#nav-main').accordion('add', {
                        title: data[i]['text'],
                        iconCls: data[i]['iconCls'],
                        selected: false,
                        content: menulist
                    });
                }
                // $.parser.parse();
                $(".panel-body .accordion-body>ul").on('click', 'li', function () {
                    $(this).siblings().removeClass('super-accordion-selected');
                    $(this).addClass('super-accordion-selected');

                    //新增一个选项卡
                    var tabUrl = $(this).data('url');
                    var tabTitle = $(this).text();
                    var iconCls = this.children[0].className;
                    //tab是否存在
                    if ($("#tt").tabs('exists', tabTitle)) {
                        $("#tt").tabs('select', tabTitle);
                    } else {
                        var content = "<iframe frameborder=0 scrolling='auto' style='width:100%;height:99%' src='" + tabUrl + "'></iframe>";
                        $('#tt').tabs('add', {
                            title: tabTitle,
                            content: content,
                            iconCls: iconCls,
                            //href: tabUrl,
                            closable: true
                        });
                    }
                });
            });


            // 修改主题
            $('#themeSetting').on('click', function () {
                var themeWin = $('#win').dialog({
                    width: 460,
                    height: 260,
                    modal: true,
                    title: '主题设置',
                    buttons: [{
                        text: '保存',
                        id: 'btn-sure',
                        handler: function () {
                            themeWin.panel('close');
                            // css
                            var themeName = $(".themeItem ul li.themeActive>div").attr('class');
                            initTheme(themeName);
                            localStorage.setItem('superTheme', themeName);
                        }
                    }, {
                        text: '关闭',
                        handler: function () {
                            themeWin.panel('close');
                        }
                    }],
                    onOpen: function () {
                        $(".themeItem").show();
                    }
                });
            });

        })


        function openPasswordModifyDialog() {
            $("#dlg").dialog("open").dialog("setTitle", "修改密码");
            url = "/admin/user/modifyPassword";
        }

        function logout() {
            $.messager.confirm("系统提示", "您确定要退出系统吗?", function (r) {
                if (r) {

                    window.location.href = "/logout";
                }
            });
        }


        function closePasswordModifyDialog() {
            $("#dlg").dialog("close");
        }

        function modifyPassword() {
            $("#fm").form("submit", {
                url: "sys/user/updatepass",
                onSubmit: function () {
                    var oldPassword = $("#oldPassword").val();
                    var newPassword = $("#newPassword").val();
                    var newPassword2 = $("#newPassword2").val();
                    if (!$(this).form("validate")) {
                        return false;
                    }
                    if (newPassword != newPassword2) {
                        $.messager.alert("系统提示", "确认新密码输入错误！");
                        return false;
                    }
                    return true;
                },
                success: function (result) {
                    console.dir(result)
                    var result = eval('(' + result + ')');
                    if (result.success) {
                        message("密码修改成功,请重新登录");
                        logout();
                        $("#dlg").dialog("close");
                    } else {
                        message("密码修改失败，请联系管理员！");
                    }
                }
            });
        }
    </script>
</head>
<body class="easyui-layout">
<div data-options="region:'north',border:false" class="super-north">
    <!--顶部-->
    <div class="super-navigation">
        <!--系统名称-->
        <div class="super-navigation-title">使用单位: [[${session.ENTEPRISE.cname}]]</div>
        <!--自定义导航-->
        <div class="super-navigation-main">
            <div class="super-setting-left">
                <ul>
                    <li><i class="fa fa-commenting-o"></i>消息</li>
                    <li><i class="fa fa-envelope-o"></i>邮件</li>
                    <li><i class="fa fa-bell-o"></i>通知</li>
                </ul>
            </div>
            <div class="super-setting-right">
                <ul>
                    <li>
                        <div class="super-setting-icon">
                            <i class="fa fa-gears"></i>
                        </div>
                        <div id="mm" class="easyui-menu">
                            <div onclick="openPasswordModifyDialog()">修改密码</div>
                            <div id="themeSetting">主题</div>
                            <div class="menu-sep"></div>
                            <div onclick="logout()">注销</div>
                        </div>
                    </li>
                    <li class="user">
                        <span class="user-icon"><img src="images/icon/1.jpg"/></span>
                        欢迎[[${session.USER.roles}]]：
                        <dl style="font-size: 20px;color: #c9302c">[[${session.USER.cname}]]</dl>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</div>
<div data-options="region:'center'" style="padding-top: 2px;">
    <!--主要内容-->
    <div id="tt" class="easyui-tabs" data-options="border:false,fit:true">
        <!--        <div title="首页" data-options="iconCls:'fa fa-home'">-->
        <!--            <div style="padding: 20px;">-->
        <!--                放点什么好呢......-->
        <!--            </div>-->
    </div>
</div>
</div>

<!--<div region="west" style="width: 200px" title="导航菜单" split="true" iconCls="icon-navigation">-->
<!--    <ul id="tree" class="easyui-tree" style="padding: 10px"></ul>-->
<!--</div>-->
<div data-options="region:'west',title:'导航菜单',border:false" class="super-west" iconCls="fa fa-bars">
    <!--左侧导航-->
    <div class="easyui-accordion" data-options="border:false" id="nav-main">

    </div>
</div>

<div region="south" style="height: 30px;padding: 5px" align="center">
    Copyright © 2019-2019 网运宝 版权所有
</div>

<div id="dlg" class="easyui-dialog" style="width: 400px;height: 180px;padding: 10px 20px"
     closed="true" buttons="#dlg-buttons">
    <form id="fm" method="post">
        <table cellspacing="8px">
            <tr>
                <td>旧密码：</td>
                <td>
                    <input type="password" id="oldPassword" name="oldPassword" class="easyui-passwordbox"
                           required="true" style="width: 200px"/>
                </td>
            </tr>
            <tr>
                <td>新密码：</td>
                <td>
                    <input type="password" id="newPassword" name="newPassword" class="easyui-passwordbox"
                           required="true" style="width: 200px"/>
                </td>
            </tr>
            <tr>
                <td>确认新密码：</td>
                <td>
                    <input type="password" id="newPassword2" name="newPassword2" class="easyui-passwordbox"
                           required="true" style="width: 200px"/>
                </td>
            </tr>
        </table>
    </form>
</div>
<div id="dlg-buttons">
    <a href="javascript:modifyPassword()" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
    <a href="javascript:closePasswordModifyDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
</div>

<!--主题设置弹窗-->
<div id="win">
    <div class="themeItem">
        <ul>
            <li>
                <div class="superGreen" style="background: #1abc9c;">green</div>
            </li>
            <li class="themeActive">
                <div class="superBlue" style="background: #3498db;">blue</div>
            </li>
            <li>
                <div class="superGray" style="background: #95a5a6;">gray</div>
            </li>
            <li>
                <div class="superAmethyst" style="background: #9b59b6;">amethyst</div>
            </li>
            <li>
                <div class="superBlack" style="background: #34495e;">black</div>
            </li>
            <li>
                <div class="superYellow" style="background: #e67e22;">yellow</div>
            </li>
            <li>
                <div class="superEmerald" style="background: #2ecc71;">emerald</div>
            </li>
            <li>
                <div class="superRed" style="background: #e74c3c;">red</div>
            </li>
        </ul>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        // 设置按钮的下拉菜单
        $('.super-setting-icon').on('click', function () {
            $('#mm').menu('show', {
                top: 50,
                left: document.body.scrollWidth - 300
            });
        });
    })


    // 勾选主题
    $(".themeItem ul li").on('click', function () {
        $(".themeItem ul li").removeClass('themeActive');
        $(this).addClass('themeActive');
    });
</script>
</body>

</html>